package group2assignone.ucm.administrator;

import group2assignone.func.Authentication;
import group2assignone.model.Administrator;
import group2assignone.model.Manager;
import group2assignone.ucm.UCController;
import group2assignone.view.MainView;
import group2assignone.view.UITool;
import java.util.ArrayList;

    /**
     * Use Case: AdminLogin<br>
     * Pre-Condition: MainView UI<br>
     * Post-Condition: UI is updated<br>
     * 1. System uploads admin details<br>
     * 2. System authenticates recieved Admin Login data<br>
     * 3. System closes the previous view<br>
     * 4. System creates the Admin Main View use case<br>
     * 5. System passes the administrator details to the use case<br>
     * 6. System starts the Admin Main View use case<br>
     * 2a.  - Administrator credentials recieved are indcorrect<br>
     *     System displays error and returns to the main UI<br>
     */
public class UCAdminLogin implements UCController {

    private Administrator adm;
    private MainView view;
    private Authentication auth;
    private boolean ok;
    ArrayList<Manager> manList;

    public UCAdminLogin(MainView view) {
        this.view = view;
        adm = new Administrator();
        auth = new Authentication();
    }


    public void run() {
        //1. System uploads admin details
        view.upload(adm);
        //2. System authenticates recieved Admin Login data
        ok = auth.authAdmin(adm);

        if (ok) {
            //3. System closes the previous view
            view.dispose();
            //4. System Opens the Admin Main View UI
            UCUIAdminMainView ucmv = UCUIAdminMainView.getInstance();
            //5. System passes the administrator details to the use case
            ucmv.setAdministrator(adm);
            //6. System starts the Admin Main View use case
            ucmv.run();

        } else {
            //    * 2a.  - Administrator credentials recieved are indcorrect
            //             System displays error and returns to the main UI
            UITool.displayError(auth.getErrorMsg(), view);
        }
    }
}






